package com.sdy.dataexchange.task;

import com.sdy.common.utils.DateUtil;
import com.sdy.dataexchange.core.schedule.DynamicScheduler;
import com.sdy.dataexchange.meta.model.MetadataJob;
import com.sdy.dataexchange.meta.service.MetadataJobService;
import com.sdy.dataexchange.meta.util.CronUtil;
import com.sdy.dataexchange.meta.job.ScheduleJob;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * @author: 王越洋
 * @version: v1.0
 * @description: com.sdy.dataexchange.task
 * @date:2019/11/15
 */
@Component
public class MetaJobTask {
    @Autowired
    private MetadataJobService metadataJobService;
    @Autowired
    private DynamicScheduler dynamicScheduler;


//    @Scheduled(cron = "0/10 * * * * ? ")
    public void scanMetaJob() throws SchedulerException {
        Date date = new Date();
        String string = DateUtil.dateToString(date, DateUtil.DATETIME_FORMAT);
        List<MetadataJob> metadataJobs = metadataJobService.queryAllModJob(string);
        for (MetadataJob mj:metadataJobs) {
            dynamicScheduler.updateCronTrigger(String.valueOf(mj.getId()),ScheduleJob.class,CronUtil.queryData(mj));
        }
    }
}
